﻿using HT.Future.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace HT.Future.Entities
{
    /// <summary>
    /// 微信用户与商户
    /// </summary>
    [Table("T_WxUserToBusiness")]
    public class WxUserToBusiness : BaseEntity
    {
        public int UserId { get; set; }
        public virtual WxUser User { get; set; }
        public int BusinessId { get; set; }
        public virtual Business Business { get; set; }
    }

    /// <summary>
    /// Fluent Api
    /// </summary>
    public class WxUserToBusinessConfiguration : IEntityTypeConfiguration<WxUserToBusiness>
    {
        public void Configure(EntityTypeBuilder<WxUserToBusiness> builder)
        {
            builder.HasOne(a => a.Business).WithMany(a => a.WxUsers).HasForeignKey(a => a.BusinessId).OnDelete(DeleteBehavior.ClientCascade);
            builder.HasOne(a => a.User).WithMany(a => a.Businesses).HasForeignKey(a => a.UserId).OnDelete(DeleteBehavior.ClientCascade);
        }
    }

}
